﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace BaoJian.member.exchange
{
    /// <summary>
    /// 订单申请
    /// </summary>
    public partial class Apply : System.Web.UI.Page
    {
        private string UserID;
        protected void Page_Load(object sender, EventArgs e)
        {
            UserID = HttpContext.Current.User.Identity.Name;
            if (!Page.IsPostBack)
            {
                BaoJian.Tools.Common.IsAuthenticated();
                BindData();
            }
        }

        void BindData()
        {
            LYQ.BLL.Product bll = new LYQ.BLL.Product();
            DataSet ds = bll.GetAllList();
            DrpPName.DataSource = ds.Tables[0];      
            DrpPName.DataBind();  
            ListItem item = new ListItem("请选择", "");
            DrpPName.Items.Insert(0, item);
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            LYQ.BLL.ExchangeProduct bll = new LYQ.BLL.ExchangeProduct();
            LYQ.Model.ExchangeProduct model = new LYQ.Model.ExchangeProduct();

            model.OrderID = bll.GetMaxOrderID();
            model.CustomerID = UserID;
            model.PID = DrpPName.SelectedValue;
            model.PName = DrpPName.SelectedItem.Text;
            model.Description = txtDescription.Text;
            model.TotalNum = Convert.ToInt32(TotalNum.Text);
            model.RegDate = DateTime.Now;
            // Convert.ToDateTime(
            model.Deadline = Convert.ToDateTime(Deadline.Value);
            model.ProduceDate = Convert.ToDateTime(ProduceDate.Value);
            model.ExpireDate = Convert.ToDateTime(ExpireDate.Value);
            model.Days = 0;
            model.Region = Region.SelectedValue;
            model.Publish = "已登记";
            model.Price = Convert.ToInt32(txtPrice.Text);
            model.BrowserCount = 0;
            model.ExchangeReason = string.Empty;
            model.CustomerIP = Context.Request.UserHostAddress;
            model.FeedBack = string.Empty;
            model.NeededProducts = txtNeededProducts.Text;

            bll.Add(model);

            Message.Visible = true;
            Message.InnerText = "提交成功";
            Content.Visible = false;

        }
    }
}
